import { DomWarBeaOtherPartBase } from "./DomWarBeaOtherPartBase";
import { GTileList } from "../../../../../../com/mui/controls/GTileList";
import { ObjCreate } from "../../../common/ObjCreate";
import { Language } from "../../../../../../extend/language/Language";
import { PageSelecter } from "../../../common/pageSelect/PageSelecter";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { Cache } from "../../../../cache/Cache";
import { MsgManager } from "../../../../manager/MsgManager";
import { SDominionBattlePreview } from "../../../../../../Message/Public/SDominionBattlePreview";
import { DomWarConst } from "../../DomWarConst";
import { SDominionBattleSituation } from "../../../../../../Message/Public/SDominionBattleSituation";
import { DataProvider } from "../../../../../../fl/data/DataProvider";
import { EffectManager } from "../../../../manager/EffectManager";
import { FilterConst } from "../../../../../component/gconst/FilterConst";
import { GCheckBox } from "../../../../../../com/mui/controls/GCheckBox";
import { GButton } from "../../../../../../com/mui/controls/GButton";
//class SiegeUnionPartBase
    
    export  class SiegeUnionPartBase extends DomWarBeaOtherPartBase
    {
        constructor(arg1: string="", arg2: Boolean=true, arg3: string="", arg4: number=590, arg5: number=480)
        {
            super(arg1, arg2, arg3, arg4, arg5);
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            this._bottomPart = new Object /* flash.display.Sprite */();
            this.addChild(this._bottomPart);
            this._bottomPart.x = 5;
            this._bottomPart.y = 320;
            this._cellList = new GTileList();
            this._cellList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this.addChild(this._cellList);
            this._checkBox = ObjCreate.createCheckBox(Language.getString(90636), 0, 0, 145, 20, this._bottomPart);
            this._checkBox.addEventListener(flash.events.Event.CHANGE, this.onSelectCheck);
            this._pageSelector = new PageSelecter();
            this._bottomPart.addChild(this._pageSelector);
            this._pageSelector.x = 365;
            this._pageSelector.y = 0;
            this._pageSelector.mode = PageSelecter.SingleMode;
            this._pageSelector.addEventListener(flash.events.Event.CHANGE, this.onPageChange);
            this._campTalkBtn = ObjCreate.createGButton(Language.getString(90638), 699, -4, 70, 25, this._bottomPart);
            this._campTalkBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            this._unionInviteBtn = ObjCreate.createGButton(Language.getString(90672), 614, -4, 70, 25, this._bottomPart);
            this._unionInviteBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        protected onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget;
            switch (loc1) 
            {
                case this._unionInviteBtn:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ToOpenInviteUI, {"type": 2}));
                    this.flashUnionBtn(false);
                    break;
                }
                case this._campTalkBtn:
                {
                    if (Cache.instance.country.isDominionPrivilege()) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ToOpenDominionUIByIndex, {"index": 3}));
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(90645));
                    }
                    break;
                }
            }
            return;
        }

        protected onSelectCheck(arg1: Object /* flash.events.Event */): void
        {
            this.onPageChange();
            return;
        }

        protected onPageChange(arg1: Object /* flash.events.Event */=null): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=0;
            var loc6=0;
            var loc7=0;
            if (this._allData) 
            {
                loc1 = [];
                if (this._checkBox.selected) 
                {
                    loc4 = this._allData.length;
                    loc5 = 0;
                    while (loc5 < loc4) 
                    {
                        if (typeof this._allData[loc5] === "sdominionbattlepreview") 
                        {
                            loc2 = this._allData[loc5];
                            if (loc2 && DomWarConst.hasMyServerInPreview(loc2)) 
                            {
                                loc1.push(loc2);
                            }
                        }
                        else if (typeof this._allData[loc5] === "sdominionbattlesituation") 
                        {
                            if ((loc3 = this._allData[loc5]) && DomWarConst.hasMyServerInSituation(loc3)) 
                            {
                                loc1.push(loc3);
                            }
                        }
                        ++loc5;
                    }
                }
                else 
                {
                    loc1 = this._allData;
                }
                if (loc1) 
                {
                    loc7 = (loc6 = (this._pageSelector.currentPage - 1)) + this._cellList.rowCount * this._cellList.columnCount;
                    this._pageData = loc1.slice(loc6, loc7);
                    this._cellList.dataProvider = new DataProvider(this._pageData);
                }
            }
            return;
        }

        public flashUnionBtn(arg1: Boolean=true): void
        {
            if (arg1) 
            {
                EffectManager.glowFilterReg(this._unionInviteBtn, [FilterConst.yellowGlowFilter]);
            }
            else 
            {
                EffectManager.glowFilterUnReg(this._unionInviteBtn);
            }
            return;
        }

        public /* override */ update(arg1: Object): void
        {
            var loc1=0;
            super.update(arg1);
            this._allData = arg1 as Array<any>;
            if (this._allData) 
            {
                loc1 = this._cellList.rowCount * this._cellList.columnCount;
                this._pageSelector.maxPage = Math.ceil(this._allData.length / loc1);
                this._pageSelector.currentPage = 1;
                this.onPageChange();
            }
            return;
        }

        public /* override */ destroy(): void
        {
            super.destroy();
            this._campTalkBtn.removeEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        protected /* var */_pageSelector: PageSelecter;

        protected /* var */_checkBox: GCheckBox;

        protected /* var */_cellList: GTileList;

        protected /* var */_campTalkBtn: GButton;

        protected /* var */_unionInviteBtn: GButton;

        protected /* var */_bottomPart: Object /* flash.display.Sprite */;

        protected /* var */_pageData: Array<any>;

        protected /* var */_allData: Array<any>;
    }
